<?php defined('IN_ADMIN') or exit('Access Denied!'); ?>

<style>.album{float:left;padding:3px;}.album input{width:143px;margin-top:4px;}</style>
<form action="/admin/album/save/<?=intval($shop_id);?>" method="post" id="myform">
  <input type="hidden" name="method" value="<?=$method;?>" />
  <div class="pad-10">
    <div class="col-tab">
      <ul class="tabBut cu-li" id="tab_setting">
        <li id="tab_setting_1" class="on">上传图片</li>
      </ul>
      <div id="show_div_1" class="content pad-10">
        <table width="100%" class="table_form">
          <tbody>
            <tr>
              <td class="y-bg">
                相册分类:
                <select name="album_cat">
                    <option>选择分类 ...</option>
                    <?php
                        foreach($cats as $cat){
                            $cats[$cat['album_cat']] = $cat['cat_name'];
                        }
                    ?>
                    <?=View::options($cats, $album_cat);?>
                </select>
                &nbsp;&nbsp;&nbsp;
                <input type="button" name="upfile" id="upfile" value="选择图片..." /> &nbsp;&nbsp;&nbsp;上传图片后，点击“确定”按钮保存
              </td>
            </tr>
            <tr>
              <td class="y-bg">
                <ul id="albumlist">
<?php
    if(isset($list) && is_array($list)){
        foreach($list as $item){
?>
        <li class="album"><img src="/admin/attach/thumb?picture=<?=$item['picture'];?>&width=220&height=150" height="110" width="150" />
           <input type="hidden" name="pictures[]" value="" /><br />
           <input type="radio" name="albums[]" class="input-text" value="<?=$item['album_id'];?>" />
           <?=h($item['name']);?>
        </li>
<?php
        }
    }
?>
                </ul></td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="bk15"></div>
      <input name="dosubmit" id="dosubmit" type="submit" value="提交" class="dialog">
    </div>
  </div>
</form>
<script type="text/javascript" language="javascript" src="<?=STATIC_URL;?>js/ajaxupload.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    //图片上传
    new AjaxUpload($("#upfile"), {
        action: '/admin/attach/upload/picture',
        name: 'picture',
        data: {
            'name'    : 'picture',
            'width'   : 220,
            'height'  : 150,
            'dosubmit': 'yes'
        },
        autoSubmit: true,
        responseType: 'json',
        onSubmit : function(file, ext){
            this.disable();
        },
        onComplete: function(file, response){
            this.enable();
            if(response.error == ""){
                html = '<li class="album"><img src="/admin/attach/thumb?picture=' + response.file + '&width=220&height=150" height="110" width="150" />'
                     + '<input type="hidden" name="pictures[]" value="' +response.file+ '" />'
                     + '<br /><input type="text" name="names[]" class="input-text" value="' +response.name.split(".")[0]+ '" /></li>'
                $('#albumlist').append(html);
            }else if(response.error){
                alert(response.error);
            }else{
                alert("文件上传接口错误，请重试！" + response);
            }
        }
    });
});
</script>

